package com.gxuwz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gxuwz.core.util.SystemContext;
import com.gxuwz.dao.impl.SysUserDao;
import com.gxuwz.pojo.SysUser;
import com.gxuwz.pojo.SysUser;
import com.gxuwz.service.ISysUserService;

@Service("sysUserService")
public class SysUserServiceImpl implements ISysUserService {

	@Autowired
	private SysUserDao sysUserDao;

	@Override
	public List<SysUser> list(SysUser entity) {
		// TODO Auto-generated method stub
		return sysUserDao.findByEntity(entity);
	}

	@Override
	public SysUser save(SysUser entity) {
		// TODO Auto-generated method stub
		entity.setUserPassword(SystemContext.passwdEncryption(entity.getUserPassword()));
		return sysUserDao.save(entity);
	}

	@Override
	public void remove(SysUser entity) {
		// TODO Auto-generated method stub
		sysUserDao.remove(entity);
	}

	@Override
	public void update(SysUser entity) {
		// TODO Auto-generated method stub
		sysUserDao.update(entity);
	}

	@Override
	public Boolean login(SysUser sysUser) {
		// TODO Auto-generated method stub
		Boolean isLogin = false;
		SysUser user = new SysUser();
		user.setUserId(sysUser.getUserId());
		List<SysUser> userList = sysUserDao.findByExample(user);
		if(userList != null && userList.size()>0){
			user = userList.get(0);
			if(SystemContext.passwdDecryption(sysUser.getUserPassword(),user.getUserPassword())){
				isLogin =true;
			}
		}
		
		
		return isLogin;
	}
	
	@Override
	public List<SysUser> findByHql(String queryString, Object[] params) {
		// TODO Auto-generated method stub
		return sysUserDao.findByHql(queryString, params);
	}

	@Override
	public List<SysUser> findByExample(Object exampleEntity) {
		// TODO Auto-generated method stub
		return sysUserDao.findByExample(exampleEntity);
	}

	@Override
	public List<SysUser> findByEntity(SysUser entity) {
		// TODO Auto-generated method stub
		return sysUserDao.findByEntity(entity);
	}

	@Override
	public SysUser findById(Integer id) {
		// TODO Auto-generated method stub
		return sysUserDao.find("form SysUser where id="+id).get(0);
	}

	@Override
	public List<SysUser> findByProperty(String property, String value) {
		// TODO Auto-generated method stub
		return sysUserDao.findByProperty(property, value);
	}

}
